import Vue from 'vue'
import App from './App'
import { jumpNext } from '@/libs/utils'
////////////////////////////////
Vue.config.productionTip = false
// 路由
import {
	router,
	RouterMount
} from './router/index.js';
import tabBar from '@/components/layout/tabBar'
import navBar from '@/components/layout/navBar'
import {
	hdNavigateBack
} from '@/libs/index.js'
import store from './store'
import config from '@/config'
// import { HANDLE_POING, PAGE_COUNT_BURY_POINT_BATCH } from '@/libs/requestBury'
import uView from "uview-ui";
import globalMixins from '@/mixins/global'
import '@/assets/css/index.scss'

Vue.mixin(globalMixins)
Vue.use(uView);
Vue.use(router)

Vue.component('tabBar', tabBar)
Vue.component('navBar', navBar)

Vue.prototype.hdNavigateBack = hdNavigateBack
Vue.prototype.$url = config.img_api
// console.log('图片访问地址', config.img_api)
// Vue.prototype.$HANDLE_POING = HANDLE_POING
// Vue.prototype.$PAGE_COUNT_BURY_POINT_BATCH = PAGE_COUNT_BURY_POINT_BATCH
Vue.prototype.jumpNext = jumpNext
Vue.prototype.$toast = title => {
  uni.showToast({
    title,
    icon: 'none'
  })
}
App.mpType = 'app'

function isPromise(obj) {
  return (
    !!obj &&
    (typeof obj === "object" || typeof obj === "function") &&
    typeof obj.then === "function"
  );
}

uni.addInterceptor({
  returnValue(res) {
    if (!isPromise(res)) {
      return res;
    }
    return new Promise((resolve, reject) => {
      res.then((res) => {
        if (res[0]) {
          reject(res[0]);
        } else {
          resolve(res[1]);
        }
      });
    });
  },
});

const app = new Vue({
  ...App,
  store
})
//v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
// #ifdef H5
RouterMount(app,router,'#app')
// #endif

// #ifndef H5
app.$mount(); //为了兼容小程序及app端必须这样写才有效果
// #endif
